import 'package:dio/dio.dart' hide Lock;
import 'package:pretty_dio_logger/pretty_dio_logger.dart';
import 'package:yp/config/config.dart';

import 'api_service.dart';
import 'header_interceptor.dart';

///dio框架的封装

class DioApi {
  static ApiService _apiService;
  static DioApi _singleton;
  DioApi() {
    var options = BaseOptions(
      // connectTimeout: 20000,
      receiveTimeout: 3000,
      baseUrl: Config.apiHost,
    );
    Dio dio = new Dio(options);
    // dio.interceptors.add(
    //   PrettyDioLogger(
    //     requestBody: true,
    //     requestHeader: false,
    //   ),
    // );
    dio.interceptors.add(HeaderInterceptor());
    _apiService = ApiService(dio: dio);
  }

  /// 单例模式
  static ApiService getInstance() {
    if (_singleton == null) {
      _singleton = DioApi();
    }
    return _getService();
  }

  static ApiService _getService() {
    return _apiService;
  }
}

class DioApi1 {
  static ApiService _apiService;
  static DioApi1 _singleton;
  DioApi1() {
    var options = BaseOptions(
      // connectTimeout: 20000,
      receiveTimeout: 3000,
      baseUrl: Config.apiHost1,
    );
    Dio dio = new Dio(options);
    // dio.interceptors.add(
    //   PrettyDioLogger(
    //     requestBody: true,
    //     requestHeader: false,
    //   ),
    // );
    dio.interceptors.add(HeaderInterceptor());
    _apiService = ApiService(dio: dio);
  }
  // 燕京啤酒
  /// 单例模式
  static ApiService getInstance() {
    if (_singleton == null) {
      _singleton = DioApi1();
    }
    return _getService();
  }

  static ApiService _getService() {
    return _apiService;
  }
}
